package com.atguigu.gmall.order.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.UserAuthUtils;
import com.atguigu.gmall.order.biz.OrderBizService;
import com.atguigu.gmall.order.entity.OrderInfo;
import com.atguigu.gmall.order.vo.OrderConfirmVo;
import com.atguigu.gmall.order.vo.OrderSubmitVo;
import com.atguigu.gmall.seckill.vo.SeckillOrderSubmitVo;
import org.apache.zookeeper.server.util.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lfy
 * @Description 订单接口
 * @create 2022-10-19 11:41
 */
@RestController("/api/inner/order")
public class OrderRpcController {



    @Autowired
    OrderBizService orderBizService;


    /**
     * 提交秒杀单
     * @param orderInfo
     * @return
     */
    @PostMapping("/seckillorder/submit")
    public Result<String> saveSeckillOrder(@RequestBody OrderInfo orderInfo){

        Long orderId = orderBizService.saveSeckillOrder(orderInfo);
        return Result.ok(orderId.toString());
    }



    /**
     * 根据订单id查询订单数据
     * @param orderId
     * @return
     */
    @GetMapping("/info/{orderId}")
    public Result<OrderInfo> getOrderInfoData(@PathVariable("orderId") Long orderId){

        Long userId = UserAuthUtils.getUserAuthInfo().getUserId();


        //根据订单id查询订单数据
        OrderInfo orderInfo = orderBizService.getOrderInfo(orderId,userId);


        return Result.ok(orderInfo);
    }

    /**
     * 获取订单确认页数据
     * @return
     */
    @GetMapping("/confirm/data")
    public Result<OrderConfirmVo> getOrderConfirmData(){
        //获取订单确认页数据
        OrderConfirmVo confirm =  orderBizService.getOrderConfirmData();
        return Result.ok(confirm);
    }
}
